﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LojaVirtual.Comuns.Clientes;
using LojaVirtual.Infra;

namespace LojaWeb.Areas.Admin.Controllers
{
	[Authorize]
    public class CompraController : Controller
    {
        private UnitOfWork db;

		public CompraController()
		{
			db = new UnitOfWork();
		}

        // GET: /Admin/Compra/
        public ViewResult Index()
        {
            return View(db.Compras.Recuperar());
        }

        // GET: /Admin/Compra/Details/5
        public ViewResult Details(int id)
        {
			Compra compra = db.Compras.Recuperar(id);
            return View(compra);
        }

        // GET: /Admin/Compra/Delete/5
        public ActionResult Delete(int id)
        {
            Compra compra = db.Compras.Recuperar(id);
            return View(compra);
        }

        // POST: /Admin/Compra/Delete/5
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Compra compra = db.Compras.Recuperar(id);
			db.Compras.Delete(compra);
            db.SalvarAlteracoes();
            return RedirectToAction("Index");
        }

		[HttpPost, ActionName("ConfirmarPagamento")]
		public ActionResult ConfirmarPagamento(int id)
		{
			db.Compras.ConfirmarPagamento(id);
			db.SalvarAlteracoes();

			return RedirectToAction("Details", new { id = id });
		}

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}